package org.kfive.nova.patterns;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: admin
 * Date: 15-2-24
 * Time: 下午12:50
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractObservable implements Observable {

    private ArrayList<Observer> observers;

    private boolean changeFlag=false;

    public AbstractObservable(){
        this.observers = new ArrayList<Observer>();
    }
    @Override
    public void registerObserver(Observer o) {
        //To change body of implemented methods use File | Settings | File Templates.
        observers.add(o);
    }

    @Override
    public void deleteObserver(Observer o) {
        //To change body of implemented methods use File | Settings | File Templates.
        int i = observers.indexOf(o);
        if(i>=0){
            observers.remove(i);
        }
    }

    @Override
    public void notifyObservers() {
        //To change body of implemented methods use File | Settings | File Templates.
        for(Observer o : observers){
            o.update();
        }
    }

    @Override
    public void setChange() {
        //To change body of implemented methods use File | Settings | File Templates.
    }
}
